﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;

namespace QLTV
{
    public partial class frmPhieuThuTienPhat : Form
    {
        public frmPhieuThuTienPhat()
        {
            InitializeComponent();
        }

        private void frmPhieuThuTienPhat_Load(object sender, EventArgs e)
        {
            txtMaPhieu.Text = (PhieuThuServices.LayMaPhieuThuMax() + 1).ToString();
            btnLapPhieu.Enabled = false;
        }

        private void btnLapPhieu_Click(object sender, EventArgs e)
        {

        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void txtMaDocGia_TextChanged(object sender, EventArgs e)
        {
            if (txtMaDocGia.Text.Trim() != "")
            {
                DocGiaDTO docgia = DocGiaService.LayThongTinDocGia(int.Parse( txtMaDocGia.Text));
                if (docgia.MaDocGia != 0)
                {
                    lblTonTai.Text = "";
                    lblTonTai.Visible = false;

                    txtHoTen.Text = docgia.HoTen;
                    txtTienNo.Text = docgia.TienNo.ToString();
                    txtConLai.Text = txtTienNo.Text;

                    btnLapPhieu.Enabled = true;
                }
                else
                {
                    txtHoTen.Text = "";
                    txtTienNo.Text = "";
                    txtConLai.Text = "";
                    btnLapPhieu.Enabled = false;
                }
            }
            else
            {
                txtHoTen.Text = "";
                txtTienNo.Text = "";
                txtConLai.Text = "";
                btnLapPhieu.Enabled = false;
            }
        }

        private void txtMaDocGia_Leave(object sender, EventArgs e)
        {
            if (txtHoTen.Text == "" && txtMaDocGia.Text.Trim() != "")
            {
                lblTonTai.Text = "!";
                lblTonTai.Visible = true;
            }
            else
            {
                lblTonTai.Text = "";
                lblTonTai.Visible = false;
            }
        }

        private void txtTienThu_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsNumber(e.KeyChar))
                e.Handled = true;

            if (char.IsControl(e.KeyChar))
                e.Handled = false;
        }

        private void txtMaDocGia_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsNumber(e.KeyChar))
                e.Handled = true;

            if (char.IsControl(e.KeyChar))
                e.Handled = false;
        }

        private void txtTienThu_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
